package com.work.formaldehyde.activityadapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.work.formaldehyde.R;
import com.work.formaldehyde.activity.JianCeJiLuActivity;
import com.work.formaldehyde.model.CityManageModel;
import com.work.formaldehyde.model.JianCeDateModel;
import com.work.formaldehyde.util.ApiUtils;
import com.work.formaldehyde.util.Url;

import org.json.JSONObject;

import java.util.ArrayList;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

public class CityManageAdapter extends BaseAdapter {
    ArrayList<String> list;
    ArrayList<CityManageModel.data> lists;
    Context context;
    boolean ok;

    public CityManageAdapter(ArrayList<CityManageModel.data> lists, ArrayList<String> list, Context context, boolean ok) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.lists = lists;
        this.context = context;
        this.ok = ok;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list != null ? list.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    private init i = new init();

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.citym_list_item, null);
        i.city_qiwen = convertView.findViewById(R.id.city_qiwen);
        i.city_title = convertView.findViewById(R.id.city_title);
        i.tianqi_qingkuang = convertView.findViewById(R.id.tianqi_qingkuang);
        i.lsdw = convertView.findViewById(R.id.lsdw);
        i.delf_text = convertView.findViewById(R.id.delf_text);
        i.two = convertView.findViewById(R.id.two);
        i.one = convertView.findViewById(R.id.one);
        i.zhuangtai = convertView.findViewById(R.id.zhuangtai);
        i.zhuangtai1 = convertView.findViewById(R.id.zhuangtai1);
        i.rdel = convertView.findViewById(R.id.rdel);
        i.lsdws = convertView.findViewById(R.id.lsdws);
        i.city_titles = convertView.findViewById(R.id.city_titles);
        i.delf_texts = convertView.findViewById(R.id.delf_texts);
        i.delf_msg = convertView.findViewById(R.id.delf_msg);
        if (position != list.size() - 1) {
            i.two.setVisibility(View.GONE);
            i.city_title.setText(lists.get(position).getCity_name());
            i.city_titles.setText(lists.get(position).getCity_name());
            i.city_qiwen.setText(lists.get(position).getLow() + "°~" + lists.get(position).getHigh() + "°");
            if (ok) {
                if (lists.get(position).getIs_remind().equals("0")) {
                    i.lsdw.setVisibility(View.GONE);
                    i.delf_text.setVisibility(View.GONE);
                }
                i.zhuangtai1.setVisibility(View.GONE);
                i.rdel.setVisibility(View.GONE);
            } else {
                if (lists.get(position).getIs_remind().equals("0")) {
                    i.lsdws.setVisibility(View.GONE);
                    i.delf_texts.setBackground(context.getResources().getDrawable(R.drawable.city_blue));
                    i.delf_msg.setText("设为默认城市");
                }
                i.tianqi_qingkuang.setVisibility(View.GONE);
                i.zhuangtai.setVisibility(View.GONE);
                i.city_qiwen.setVisibility(View.GONE);
            }
        } else if (position == list.size() - 1 && !ok) {
            i.one.setVisibility(View.GONE);
            i.two.setVisibility(View.GONE);
        } else {
            i.one.setVisibility(View.GONE);
        }

        convertView.setTag(i);
        return convertView;
    }


    public static class init {
        //首页list的子控件
        TextView city_qiwen, city_title;
        ImageView tianqi_qingkuang, lsdw;
        LinearLayout delf_text;
        RelativeLayout zhuangtai, zhuangtai1;
        //修改状态下的控件
        // city_title和city_titles的值取同一个
        ImageView rdel;
        ImageView lsdws;
        TextView city_titles, delf_msg;
        LinearLayout delf_texts, two;
        RelativeLayout one;
    }
}

